// UIView 类扩展, 实现之间读取并设置坐标, 宽高, 大小等方法, 比较方便

import UIKit
//UIView 的类扩展
extension UIView {
    //宽度
    var width: CGFloat {
        //get 方法
        get{
            return frame.size.width
        }
        //set 方法
        set{
            var frame = self.frame
            frame.size.width = newValue
            self.frame = frame
        }
    }
    //高度
    var height: CGFloat {
        get{
            return frame.size.height
        }
        set{
            var frame = self.frame
            frame.size.height = newValue
            self.frame = frame
        }
    }
    //X 坐标
    var x: CGFloat {
        get{
            return frame.origin.x
        }
        set{
            var frame = self.frame
            frame.origin.x = newValue
            self.frame = frame
        }
    }
    //Y 坐标
    var y: CGFloat {
        get{
            return frame.origin.y
        }
        set{
            var frame = self.frame
            frame.origin.y = newValue
            self.frame = frame
        }
    }
    //中心点 X 坐标
    var centerX: CGFloat {
        get{
            return center.x
        }
        set{
            var center = self.center
            center.x = newValue
            self.center = center
        }
    }
    //中心点 Y 坐标
    var centerY: CGFloat {
        get{
            return center.y
        }
        set{
            var center = self.center
            center.y = newValue
            self.center = center
        }
    }
    //大小
    var size: CGSize {
        get{
            return frame.size
        }
        set{
            var frame = self.frame
            frame.size = newValue
            self.frame = frame
        }
    }
    
}